﻿package util {
	import flash.system.System;	
	import flash.display.Sprite;	
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import util.Evt;
	
	/**
	 * ...
	 * @author 
		========================================
		iPartners Interactive Part
		author : ��� (pass4u@ipartners.co.kr)
		Date : 
		========================================
	 */
		public class  XmlLoader extends URLLoader
	{
		private var HDL:Object;
		private var SCOPE :Object;
		private var xmlUrl:String;
		private var RootNode:String
		
		
		public function XmlLoader(scope:Object, url:String, hdl:Object,rootNode:String=null):void {
			this.SCOPE = scope;
			this.HDL = hdl;
			
			this.xmlUrl = url;
			
			RootNode = rootNode;
			
			
			Evt.add([this], ["complete"], ldHdl);
			//Evt.add([this],["progress"], ldHdl);
			this.load(new URLRequest(url));
		}
		private function ldHdl(e:Event):void{
			trace(xmlUrl + "로드성공");
//			trace(e.target.data);
			if(RootNode!=null){
				var temp:String=e.target.data;
				var idx:int = temp.lastIndexOf(RootNode)				
				idx+=RootNode.length;
//				trace("idx",idx);
				temp=temp.substring(0,idx);
				//trace(temp);
				HDL.apply(SCOPE, new Array(new XML(temp)));
				return;
				
			}
			try{
				HDL.apply(SCOPE, new Array(new XML(e.target.data)));
			}catch(ee:Error){
				trace("============== XML 에러 ==================")
				trace(ee)
				trace("==============+++++++++==================")
			}
		}
		
	}
	
}